草庐IT

node.js - nodejs异步的while

全部标签

javascript - 如何计算 JavaScript 中异步函数的执行时间?

我想计算异步函数(async/await)在JavaScript中花费了多长时间。可以这样做:constasyncFunc=asyncfunction(){};constbefore=Date.now();asyncFunc().then(()=>{constafter=Date.now();console.log(after-before);});但是,这不起作用,因为promise回调在新的微任务中运行。IE。在asyncFunc()结束和then(()=>{})开始之间,任何已经排队的微任务将首先被触发,它们的执行时间将为考虑在内。例如:constasyncFunc=asyncf

javascript - NodeJS 事件循环中的轮询阶段

我正在通过Nodedocs对于事件循环,我感到非常困惑。它说——timers:thisphaseexecutescallbacksscheduledbysetTimeout()andsetInterval().I/Ocallbacks:executesalmostallcallbackswiththeexceptionofclosecallbacks,theonesscheduledbytimers,andsetImmediate().idle,prepare:onlyusedinternally.poll:retrievenewI/Oevents;nodewillblockherew

javascript - NodeJS - Jest 单元测试 process.on 回调中的 setTimeout

我正在尝试在我的process.on('SIGTERM')回调中使用Jest对计时器进行单元测试,但它似乎从未被调用过。我正在使用jest.useFakeTimers()虽然它似乎在一定程度上模拟了setTimeout调用,但它并没有在setTimeout.mock中结束检查时对象。我的index.js文件:process.on('SIGTERM',()=>{console.log('GotSIGTERM');setTimeout(()=>{console.log('Timerwasrun');},300);});setTimeout(()=>{console.log('Timer2w

javascript - Express.js 服务器端渲染 - 请求 '/json/version/

我有一个快速服务器正在运行以预呈现我的React应用程序。我有一个路由文件,该文件将HomeContainer与基本路由/匹配,所有其他路由都与未找到的页面匹配。importHomeContainerfrom'containers/home-container/home-container';importPageNotFoundfrom'components/page-not-found/page-not-found';constroutes=[{path:'/',exact:true,component:HomeContainer},{path:'*',component:PageN

javascript - 为什么+=(加法赋值,加上等于)在 Node 中这么慢?

这个问题在这里已经有了答案:Whatdoescompoundlet/constassignmentmean?(1个回答)关闭5年前。在某些版本的node中,a+=b明显比a=a+b慢,但在浏览器和更高版本中类似。是什么导致它们运行如此不同?nodev6.10.0(V85.1.281.93),慢75%,或者反向快4倍nodev8.0.0(V85.8.283.41),慢86%,或者反向快7倍nodev8.2.1(V85.8.283.41),慢86%,或者反向快7倍nodev8.3.0(V86.0.286.52),类似nodev8.7.0(v86.1.534.42),类似nodev8.9.2

javascript - Vue.js : "TypeError: Cannot set property props of#<Object> which has only a getter"

我正在尝试实例化一个Vue组件,但出现错误:[Vuewarn]:Errorinrender:"TypeError:Cannotsetpropertypropsof#whichhasonlyagetter"(foundin)我也在使用库vuedraggable但我认为这个问题更多的是Vue问题而不是vuedraggable问题。下面是我的代码。这里是draggable-list.vue可拖动列表.jsconstdraggable=require("vuedraggable");module.exports={name:"draggable-list",components:{dragga

javascript - Typescript 使用 Rx.js 过滤器运算符区分联合类型?

typescript支持discriminatedunions.如何将与Rxjs相同的概念扩展到filter下面例子中的运算符?interfaceSquare{kind:'square';width:number;}interfaceCircle{kind:'circle';radius:number;}interfaceCenter{kind:'center';}typeShape=Square|Circle|Center;constobs$:Observable=of({kind:'square',width:10});//Expectedtype:Observable//Actu

javascript - 使用 Angular 2 和 Node.js 下载不支持 Firefox 的 PDF

我正在从NodeJavaScript后端获取base64字符串。但它不像Chrome那样工作。我在网上找不到任何解决方案。在API调用中获得200状态,但它没有在Firefox中下载文件,而相同的代码在Chrome中运行良好。这是我的代码::staticdownloadFile(fileName:string,fileMimeType:string,uri:string){constdataURI=uri;constblob=this.dataURIToBlob(dataURI);consturl=URL.createObjectURL(blob);constblobAnchor=do

javascript - 带有异步 forEach 循环的磁带 "test exited without ending"错误

我在做什么编辑:我创建了一个repo使用我的问题的简化版本重现问题。我正在尝试使用browserstack设置自动化前端测试,selenium-webdriver和tape.Moreabouttape这个想法是定义多个浏览器和设备,这些浏览器和设备必须用X数量的给定测试一个接一个地进行测试。在下面的例子中,我在OSX上只定义了一个测试和两个浏览器。为了只定义一次浏览器并处理测试,我创建了一个repotest-runner,它应该作为dev-dependency添加到需要的repos在给定的设备和浏览器上测试。test-runner使所有需要的测试都通过,启动第一个浏览器,在该浏览器上运

javascript - 为什么两个 JS 日期对象实例化不同?

我想启用/禁用基于日期选择器的按钮,并且我有一个这样的检查设置:publicdateChanged=false;publicavailableFromDate:Date;publicavailableToDate:Date;initDatepickers(){constcurrentDay=newDate();this.availableFromDate=currentDay;this.availableToDate=currentDay;}privatedateCheck(){if((this.availableFromDate>this.availableToDate)||(thi